package com.atguigu.service.Impl;

import com.atguigu.dao.DictDao;
import com.atguigu.entity.Dict;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @title：
 * @author：Yu
 * @create：2023-02-07 16:01
 * @description：
 */
@DubboService
public class DictServiceImpl implements DictService {
    @Autowired
    private DictDao dictDao;

    @Override
    public List<Map<String, Object>> findZnodes(Long id) {
        List<Map<String, Object>> list = new ArrayList<>();
        List<Dict> list1 = dictDao.findListByParentId(id);
        for (Dict dict : list1) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", dict.getId());
            map.put("name", dict.getName());
            map.put("isParent", dictDao.findListByParentId(dict.getId()).size() > 0 ? true : false);
            list.add(map);
        }
        return list;
    }

    @Override
    public List<Dict> findById(Long id) {
        return dictDao.findListByParentId(id);
    }

    @Override
    public List<Dict> findProvice(Long id) {
        List<Dict> list = dictDao.findListByParentId(id);
        return list;
    }

    @Override
    public List<Dict> findAll() {
        List<Dict> list = dictDao.findAll();
        return list;
    }

    @Override
    public List<Dict> findByCode(String code) {
        Dict byCode = dictDao.findByCode(code);
        return dictDao.findListByParentId(byCode.getId());
    }
}
